using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using EntLibContrib.Validation.Design.Nodes;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.Design;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.Design.ValidatorNodes;
using System.Windows.Forms;

namespace EntLibContrib.Validation.Design
{
    class ValidationCommandRegistrar : CommandRegistrar
    {
        public ValidationCommandRegistrar(IServiceProvider serviceProvider)
            :base(serviceProvider)
        {
        }

        public override void Register()
        {

            ConfigurationUICommand uiCommand = ConfigurationUICommand.CreateMultipleUICommand(
                base.ServiceProvider, 
                Resources.AddValidationTypeFromStringCommandName, 
                Resources.AddValidationTypeFromStringCommand, 
                new AddTypeFromStringNodeCommand(base.ServiceProvider), 
                typeof(TypeNode));

            base.AddUICommand(uiCommand, typeof(ValidationSettingsNode));

            ConfigurationUICommand testValidatorCommand= new ConfigurationUICommand(
                base.ServiceProvider,
                Resources.TestValidatorCommandName,
                Resources.TestValidatorCommand, CommandState.Enabled,
                new TestValidatorCommand(this.ServiceProvider), Shortcut.None, InsertionPoint.Action, null);

            base.AddUICommand(testValidatorCommand, typeof(ContainsCharactersValidatorNode));
            base.AddUICommand(testValidatorCommand, typeof(DateRangeValidatorNode));
            base.AddUICommand(testValidatorCommand, typeof(DomainValidatorNode));
            base.AddUICommand(testValidatorCommand, typeof(EnumConversionValidatorNode));
            base.AddUICommand(testValidatorCommand, typeof(RegexValidatorNode));
            base.AddUICommand(testValidatorCommand, typeof(RelativeDateTimeValidatorNode));
            base.AddUICommand(testValidatorCommand, typeof(StringLengthValidatorNode));
            base.AddUICommand(testValidatorCommand, typeof(TypeConversionValidatorNode));

            AddValidatorCommands(typeof(CollectionCountValidatorNode), Resources.AddCollectionCountValidatorCommandName, Resources.AddCollectionCountValidatorCommand);
            AddValidatorCommands(typeof(ExternallyConfiguredObjectCollectionValidatorNode), Resources.AddExternallyConfiguredObjectCollectionValidatorCommandName, Resources.AddExternallyConfiguredObjectCollectionValidatorCommand);
            AddValidatorCommands(typeof(ExternallyConfiguredObjectValidatorNode), Resources.AddExternallyConfiguredObjectValidatorNodeCommandName, Resources.AddExternallyConfiguredObjectValidatorNodeCommand);
            AddValidatorCommands(typeof(CompositeRulesetValidatorNode), Resources.AddCompositeRulesetValidatorCommandName, Resources.AddCompositeRulesetValidatorNodeCommand);
            AddValidatorCommands(typeof(EnumDefinedValidatorNode), Resources.AddEnumDefinedValidatorCommandName, Resources.AddEnumDefinedValidatorCommand);
			AddValidatorCommands(typeof(TypeValidatorNode), Resources.AddTypeValidatorCommandName, Resources.AddTypeValidatorCommand);
		}

        protected virtual void AddValidatorCommands(Type validatorNodeType, string text, string longText)
        {
            AddMoveUpDownCommands(validatorNodeType);

            AddDefaultCommands(validatorNodeType);

            AddMultipleChildNodeCommand(
                text,
                longText,
                validatorNodeType,
                typeof(FieldNode));

            AddMultipleChildNodeCommand(
                text,
                longText,
                validatorNodeType,
                typeof(MethodNode));

            AddMultipleChildNodeCommand(
                text,
                longText,
                validatorNodeType,
                typeof(PropertyNode));


            AddMultipleChildNodeCommand(
                text,
                longText,
                validatorNodeType,
                typeof(SelfNode));


            AddMultipleChildNodeCommand(
                text,
                longText,
                validatorNodeType,
                typeof(AndCompositeValidatorNode));


            AddMultipleChildNodeCommand(
                text,
                longText,
                validatorNodeType,
                typeof(OrCompositeValidatorNode));
        }
    }
}
